package model;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class WeatherSource {

	String sourceName;
	String sourcePath;
	
	public WeatherSource(String sourceName, String sourcePath) {
		this.sourceName = sourceName;
		this.sourcePath = sourcePath;
	}



	public String getSourceName() {
		return sourceName;
	}



	public void setSourceName(String sourceName) {
		this.sourceName = sourceName;
	}



	public String getSourcePath() {
		return sourcePath;
	}



	public void setSourcePath(String sourcePath) {
		this.sourcePath = sourcePath;
	}



	public int getTempForCity(String cityName) throws IOException{
		int temperatureInt = 0;
		FileReader fr = new FileReader(sourcePath);
		BufferedReader br = new BufferedReader(fr);
		String s;
		while ((s = br.readLine()) != null) {
			String[] seperatedValues = s.split("=");
			if (seperatedValues[0].equals(cityName)){
				String temperatureString = seperatedValues[1];
				System.out.println("Temperature was found in file at: " + temperatureString  + "degrees");
				temperatureInt = Integer.valueOf(temperatureString);
			}
		}
		fr.close();
		
		
		
		return temperatureInt;
		
	}
}
